package com.crayon.scoreboard.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.aphidmobile.flip.FlipViewController;
import com.crayon.scoreboard.R;
import com.crayon.scoreboard.views.NumberTextView;


/**
 * com.crayon.scoreboard.fragment.FlipTextViewFragment
 * A simple {@link android.support.v4.app.Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link com.crayon.scoreboard.fragment.FragmentSetScore.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link com.crayon.scoreboard.fragment.FragmentSetScore#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FragmentSetScore extends FlipTextViewFragment {



    public static FragmentSetScore newInstance(int bgcolor) {
        FragmentSetScore fragment = new FragmentSetScore();
        Bundle args = new Bundle();
        args.putInt(PARAM_COLOR, bgcolor);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        flipView = new FlipViewController(inflater.getContext());


        flipView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return 99;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                NumberTextView view;

                if (convertView == null) {
                    final Context context = parent.getContext();
                    view = new NumberTextView(context, position);
                    view.setTextSize(context.getResources().getDimension(R.dimen.textSizeSett));
                    view.setBackgroundColor(getArguments().getInt(PARAM_COLOR));
                } else {
                    view = (NumberTextView) convertView;
                    view.setNumber(position);
                }

                return view;
            }
        });

        return flipView;
    }


}
